﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************

Imports System.Xml

''' <summary>
''' Item that stores the help file info
''' </summary>
''' <remarks></remarks>
Public Class HelpList
    Private _HelpKey As String = String.Empty
    Private _IsLocal As Boolean = False
    Private _description As String = String.Empty
    Private _Category As String = String.Empty
    Private _url As String = String.Empty
    Public Overrides Function ToString() As String
        Return _description.ToString()
    End Function
    Public Property Category() As String
        Get
            Return _Category
        End Get
        Set(ByVal value As String)
            _Category = value
        End Set
    End Property
    Public Property Description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property
    Public Property HelpKey() As String
        Get
            Return _HelpKey
        End Get
        Set(ByVal value As String)
            _HelpKey = value
        End Set
    End Property
    Public Property IsLocal() As Boolean
        Get
            Return _IsLocal
        End Get
        Set(ByVal value As Boolean)
            _IsLocal = value
        End Set
    End Property
    Public Property Url() As String
        Get
            Return _url
        End Get
        Set(ByVal value As String)
            _url = value
        End Set
    End Property


End Class
''' <summary>
''' Collection Of help Files
''' </summary>
''' <remarks></remarks>
Public Class HelpFileCollection
    Inherits ObjectModel.KeyedCollection(Of String, HelpList)
    Protected Overrides Function GetKeyForItem(ByVal item As HelpList) As String
        Return item.HelpKey.ToUpper
    End Function
    Public Function GetUrl(ByVal Key As String) As String
        Return Me.Item(Key).Url
    End Function
    Public Sub LoadList(Optional ByVal Path As String = "")
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim Tobj As XmlNode = Nothing

        m_xmld = New XmlDocument()
        'Load the Xml file
        If Path = "" Then
            m_xmld.Load(My.Application.Info.DirectoryPath & "\Data\HELP\HELP.xml")
        Else
            m_xmld.Load(Path)
        End If

        m_nodelist = m_xmld.GetElementsByTagName("Help")
        Me.ClearItems()
        For Each Tobj In m_nodelist
            Dim o_Help As New HelpList
            o_Help.HelpKey = Tobj.Item("HelpKey").InnerText
            ' Debug.Print(Tobj.Item("IsLocal").InnerText.ToUpper)
            If Tobj.Item("IsLocal").InnerText.ToUpper = "TRUE" Then
                o_Help.IsLocal = True
            End If
            If Tobj.Item("Cat") IsNot Nothing Then
                o_Help.Category = Tobj.Item("Cat").InnerText
            End If
            o_Help.Description = Tobj.Item("Description").InnerText
            o_Help.Url = Tobj.Item("Url").InnerText

            Me.Add(o_Help)
        Next

    End Sub
End Class
